package main

import (
	"Xorm/model"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"xorm.io/xorm"
)

var engine *xorm.Engine

func main() {

	var err error
	engine, err = xorm.NewEngine("mysql", "root:123456@(127.0.0.1:3306)/gorm_text?charset=utf8")
	if err != nil {
		panic("连接出错")
	}
	engine.ShowSQL(true) // 是否输出sql日记
	//fmt.Println(engine.DBMetas())								// 输出数据表

	//engine.Sync2(new(model.User))								// 同步数据库
	//user1 := model.User{ 										// 实例化一个对象
	//	Username:   "马牛逼1",
	//	Secret:     "666",
	//	Password:   "123456",
	//	Email:      "122",
	//	CreateTime: time.Time{},
	//	UpdateTime: time.Time{},
	//}
	//engine.Insert(user1) 										//  插入实例化的数据
	user := new(model.User)
	//engine.Where("username = ?", "马牛逼").Get(user) 			// 获取一条数据
	//fmt.Println("%v", user)
	//users := make([]model.User, 0)
	//engine.Where("username = ?", "马牛逼").Find(&users) 		// 获取所有数据
	//fmt.Println("%v", users)
	//total, _ := engine.Where("Email = ?", 12).Count(user)		// 统计数据
	//print(total)

	//res, _ := engine.Where("username = ?", "马牛逼").Exist(user)
	//print(res)

	fmt.Printf("%v\n", user)

}
